package book

import (
	"context"
)

// BookRepository 书籍仓储接口
type BookRepository interface {
	// 基础操作
	Create(ctx context.Context, book *Book) error
	GetByID(ctx context.Context, id uint) (*Book, error)
	GetBySlug(ctx context.Context, slug string) (*Book, error)
	Update(ctx context.Context, book *Book) error
	Delete(ctx context.Context, id uint) error

	// 列表和查询
	List(ctx context.Context, offset, limit int, filters map[string]interface{}) ([]*Book, int64, error)
	ListByCategory(ctx context.Context, categoryID uint, offset, limit int) ([]*Book, int64, error)
	ListByRecommended(ctx context.Context, recommended int, offset, limit int) ([]*Book, int64, error)
	Search(ctx context.Context, keyword string, offset, limit int) ([]*Book, int64, error)

	// 回收站相关
	ListSoftDeleted(ctx context.Context, offset, limit int) ([]*Book, int64, error)
	GetSoftDeletedByID(ctx context.Context, id uint) (*Book, error)
	Restore(ctx context.Context, id uint) error
	HardDelete(ctx context.Context, id uint) error

	// 检查和统计
	CheckSlugExists(ctx context.Context, slug string, excludeID uint) (bool, error)
	CountByCategoryID(ctx context.Context, categoryID uint) (int64, error)
}

// ChapterRepository 章节仓储接口
type ChapterRepository interface {
	// 基础操作
	Create(ctx context.Context, chapter *Chapter) error
	GetByID(ctx context.Context, id uint) (*Chapter, error)
	GetByBookIDAndSlug(ctx context.Context, bookID uint, slug string) (*Chapter, error)
	GetByBookIDAndOrder(ctx context.Context, bookID uint, order int) (*Chapter, error)
	Update(ctx context.Context, chapter *Chapter) error
	Delete(ctx context.Context, id uint) error

	// 列表和查询
	ListByBookID(ctx context.Context, bookID uint, offset, limit int) ([]*Chapter, int64, error)
	GetPrevChapter(ctx context.Context, bookID uint, currentOrder int) (*Chapter, error)
	GetNextChapter(ctx context.Context, bookID uint, currentOrder int) (*Chapter, error)
	SearchInBook(ctx context.Context, bookID uint, keyword string, offset, limit int) ([]*Chapter, int64, error)

	// 排序相关
	GetMaxOrderByBookID(ctx context.Context, bookID uint) (int, error)
	ReorderChapters(ctx context.Context, bookID uint, orderMap map[uint]int) error

	// 回收站相关
	ListSoftDeleted(ctx context.Context, bookID uint, offset, limit int) ([]*Chapter, int64, error)
	GetSoftDeletedByID(ctx context.Context, id uint) (*Chapter, error)
	Restore(ctx context.Context, id uint) error
	HardDelete(ctx context.Context, id uint) error

	// 批量操作
	BatchCreate(ctx context.Context, chapters []*Chapter) error
	BatchDelete(ctx context.Context, ids []uint) error
}

// RecycleBinRepository 回收站仓储接口
type RecycleBinRepository interface {
	// 基础操作
	Create(ctx context.Context, item *RecycleItem) error
	GetByID(ctx context.Context, id uint) (*RecycleItem, error)
	GetByItemIDAndType(ctx context.Context, itemID uint, itemType string) (*RecycleItem, error)
	Update(ctx context.Context, item *RecycleItem) error
	Delete(ctx context.Context, id uint) error

	// 列表和查询
	List(ctx context.Context, offset, limit int) ([]*RecycleItem, int64, error)
	ListByType(ctx context.Context, itemType string, offset, limit int) ([]*RecycleItem, int64, error)

	// 批量操作和清理
	BatchDelete(ctx context.Context, ids []uint) error
	DeleteByType(ctx context.Context, itemType string) error
	Clear(ctx context.Context) error
}
